#include<iostream>
#include<string>
#include<unistd.h>
#include<pthread.h>
#include<cstring>
#include<cstdio>
void* routine(void* args)
{
    pthread_detach(pthread_self());
    int cnt = 5;
    while(cnt--)
    {
        std::cout << "子线程名字" << std::endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,routine,(void*) "hhh");
    //pthread_detach(tid);//分离指定线程
    int cnt = 5;
    while(cnt--)
    {
        std::cout << "main 线程名字" << std::endl;
        sleep(1);
    }
    sleep(10);
    int n = pthread_join(tid,nullptr);
    if(n != 0)
    {
        std::cout << "线程已被分离" << std::endl;
    }
    else
    {
        std::cout << "www" << std::endl;
    }
    return 0;
}
//线程分离开